﻿using Cuofrisp.Core.ParallelCore.Tools;

namespace Cuofrisp.Core.ParallelCore
{
    public partial class ParallelCuofrispCalculator
    {
        private void SetCurvature(CuofrispResult result)
        {
            _ = Parallel.For(0, result.Curvature.Length,
                this.parallelOptions,
                (aBCD) => {
                    var (a, b, c, d) = aBCD.As4dIndex(result.VariableCount);
                    var items = Enumerable.Range(0, result.VariableCount).Select(
                        (t) => {
                            var item1 = result.Christoffel[t, b, d] * result.Christoffel[a, t, c];
                            var item2 = result.Christoffel[t, b, c] * result.Christoffel[a, t, d];
                            return item1 - item2;
                        });

                    var r = result.ChristoffelDerivative[a, b, d, c]
                        - result.ChristoffelDerivative[a, b, c, d];
                    foreach (var item in items)
                        r += item;
                    result.Curvature[a, b, c, d] = this.simplifier.Simplify(r);
                });
        }
    }
}